package com.swinginwind.flexutils.components.autoCompleteComboBox
{
	/**
	 * @author jimmy
	 * @E-mail: swinginwind@gmail.com
	 * @version 1.0.0
	 * 创建时间：2013-8-19 下午8:09:20
	 * 
	 */
	public class CustomAutoCompleteBox extends AutoCompleteComboBox
	{
		private var _filterFields:Array;
		
		
		public function CustomAutoCompleteBox()
		{
			super();
		}
		
		public function get filterFields():Array
		{
			return _filterFields;
		}

		public function set filterFields(value:Array):void
		{
			_filterFields = value;
		}

		override protected function autoCompleteFilter(item:Object):Boolean
		{
			if(!item)
				return false;
			
			var regEx : RegExp = new RegExp('.*' + this.typeAheadText + '.*' ,'i');
			
			// probably want to use match on this string
			
			if(_filterFields && _filterFields.length > 0)
			{
				for each(var str:String in _filterFields)
				{
					if(item[str] && item[str].toString().match(regEx))
					{
						return true;
					}
				}
			}
			else
			{
				var label : String = this.itemToLabel(item);
				if(label.match(regEx)){
					return true;
				}	
			}
			return false;
		}
	}
}